home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / exampleCode / viewkit / VCal / PrefDialog.c++ < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  10.1 KB  |  332 lines

  1. /*
  2.  * Copyright (C) 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17. #include <stdio.h>
  18. #include <stdlib.h>
  19. #include "PrefDialog.h"
  20. #include "VCal.h"
  21. #include "Preferences.h"
  22. #include <Vk/VkPrefItem.h>
  23. #include <Vk/VkWarningDialog.h>
  24.  
  25. PrefDialog::PrefDialog(VCal *o, Preferences *p, const char *name)
  26. : VkPrefDialog(name)
  27. {
  28.   owner = o;
  29.   pref = p;
  30.  
  31.   list = new VkPrefList("preferences");
  32.   alarmGroup = new VkPrefGroup("alarmGroup", True);
  33.   alarmExtra = new VkPrefGroup("alarmExtra", False, True);
  34.   dayGroup = new VkPrefGroup("dayGroup", True);
  35.   day1 = new VkPrefGroup("day1", False, True);
  36.   day2 = new VkPrefGroup("day2", False, True);
  37.   day3 = new VkPrefGroup("day3", False, True);
  38.   configGroup = new VkPrefGroup("configGroup", True);
  39.   config1 = new VkPrefGroup("config1", False, True);
  40.   config2 = new VkPrefGroup("config2", False, True);
  41.   config3 = new VkPrefGroup("config3", False, True);
  42.   saveGroup = new VkPrefGroup("saveGroup");
  43.   filename = new VkPrefText("filename", 40);
  44.   advance = new VkPrefText("advance");
  45.   update = new VkPrefText("update");
  46.   snooze = new VkPrefText("snooze");
  47.   lates = new VkPrefToggle("latest", True);
  48.   autoSave = new VkPrefToggle("autoSave", True);
  49.   annotate = new VkPrefToggle("annotate", True);
  50.   updateIcon = new VkPrefToggle("updateIcon", True);
  51.   updateIconDate = new VkPrefToggle("updateIconDate", True);
  52.   clock24 = new VkPrefToggle("clock24", True);
  53.   alarm1 = new VkPrefGroup("alarm1", False, True);
  54.   alarm2 = new VkPrefGroup("alarm2", False, True);
  55.   alarm3 = new VkPrefGroup("alarm3", False, True);
  56.   alarms = new VkPrefToggle("alarms", True);
  57.   notifyPopup = new VkPrefToggle("notifyPopup", True);
  58.   notifyBell = new VkPrefToggle("notifyBell", True);
  59.   notifyConfirmDelete = new VkPrefToggle("notifyConfirmDelete", True);
  60.   notifyMail = new VkPrefToggle("notifyMail", True);
  61.   notifyCommand = new VkPrefText("notifyCommand", 40);
  62.   annotateDay = new VkPrefToggle("annotateDay", True);
  63.   hideMenu = new VkPrefToggle("hideMenu", True);
  64.   annotateMonth = new VkPrefToggle("annotateMonth", True);
  65.   restricted = new VkPrefToggle("restricted", True);
  66.   apptLength = new VkPrefText("apptLength");
  67.   gridLength = new VkPrefText("gridLength");
  68.   apptSubdiv = new VkPrefText("apptSubdiv");
  69.   snapInterval = new VkPrefText("snapInterval");
  70.   restrictStart = new VkPrefText("restrictStart");
  71.   restrictStop = new VkPrefText("restrictStop");
  72.   space1 = new VkPrefEmpty();
  73.   space2 = new VkPrefEmpty();
  74.   space3 = new VkPrefEmpty();
  75.   
  76.   config1->addItem(hideMenu);
  77.   config1->addItem(updateIcon);
  78.   config1->addItem(updateIconDate);
  79.   config2->addItem(annotateMonth);
  80.   config2->addItem(lates);
  81.   config2->addItem(clock24);
  82.   config3->addItem(snooze);
  83.   config3->addItem(update);
  84.   configGroup->addItem(config1);
  85.   configGroup->addItem(config2);
  86.   configGroup->addItem(config3);
  87.   alarmGroup->addItem(alarm1);
  88.   alarmGroup->addItem(alarm2);
  89.   alarmGroup->addItem(alarm3);
  90.   alarm1->addItem(alarms);
  91.   alarm1->addItem(annotateDay);
  92.   alarm2->addItem(notifyPopup);
  93.   alarm2->addItem(notifyBell);
  94.   alarm3->addItem(notifyConfirmDelete);
  95.   alarm3->addItem(notifyMail);
  96.   alarmExtra->addItem(notifyCommand);
  97.   alarmExtra->addItem(advance);
  98.   day1->addItem(apptLength);
  99.   day1->addItem(gridLength);
  100.   day2->addItem(apptSubdiv);
  101.   day2->addItem(snapInterval);
  102.   day3->addItem(restricted);
  103.   day3->addItem(restrictStart);
  104.   day3->addItem(restrictStop);
  105.   dayGroup->addItem(day1);
  106.   dayGroup->addItem(day2);
  107.   dayGroup->addItem(day3);
  108.   saveGroup->addItem(filename);
  109.   saveGroup->addItem(annotate);
  110.   saveGroup->addItem(autoSave);
  111.  
  112.   list->addItem(configGroup);
  113.   list->addItem(space1);
  114.   list->addItem(alarmGroup);
  115.   list->addItem(alarmExtra);
  116.   list->addItem(space2);
  117.   list->addItem(dayGroup);
  118.   list->addItem(space3);
  119.   list->addItem(saveGroup);
  120.  
  121.   setItem(list);
  122.   updateDisplay();
  123. }
  124.  
  125. PrefDialog::~PrefDialog()
  126. {
  127.   list->deleteChildren();
  128.   delete list;
  129. }
  130.  
  131. /**********************************************************************/
  132.  
  133. void
  134. PrefDialog::updateDisplay()
  135. {
  136.   char str[256];
  137.  
  138.   alarms->setValue(pref->alarms());
  139.   notifyPopup->setValue(pref->notifyPopup());
  140.   notifyBell->setValue(pref->notifyBell());
  141.   notifyConfirmDelete->setValue(pref->notifyConfirmDelete());
  142.   notifyMail->setValue(pref->notifyMail());
  143.   notifyCommand->setValue(pref->notifyCommand());
  144.   annotateDay->setValue(pref->annotateDay());
  145.   advance->setValue(pref->advanceWarning());
  146.   sprintf(str, "%d", pref->snoozeMinutes());
  147.   snooze->setValue(str);
  148.   hideMenu->setValue(pref->hideMenuBar());
  149.   updateIcon->setValue(pref->updateIconName());
  150.   updateIconDate->setValue(pref->updateIconDate());
  151.   clock24->setValue(pref->clock24());
  152.   lates->setValue(pref->showLates());
  153.   sprintf(str, "%d", pref->updateInterval());
  154.   update->setValue(str);
  155.   filename->setValue(pref->filename());
  156.   autoSave->setValue(pref->saveChangesAutomatically());
  157.   annotate->setValue(pref->annotateFile());
  158.   annotateMonth->setValue(pref->annotateMonth());
  159.   restricted->setValue(pref->restricted());
  160.   sprintf(str, "%d", pref->apptLength());
  161.   apptLength->setValue(str);
  162.   sprintf(str, "%d", pref->gridLength());
  163.   gridLength->setValue(str);
  164.   sprintf(str, "%d", pref->apptSubdiv());
  165.   apptSubdiv->setValue(str);
  166.   sprintf(str, "%d", pref->snapInterval());
  167.   snapInterval->setValue(str);
  168.   sprintf(str, "%d", pref->restrictStart());
  169.   restrictStart->setValue(str);
  170.   sprintf(str, "%d", pref->restrictStop());
  171.   restrictStop->setValue(str);
  172.  
  173.   list->updateValue();
  174. }
  175.  
  176. /**********************************************************************/
  177.  
  178. void
  179. PrefDialog::apply(Widget, XtPointer)
  180. {
  181.   Boolean changed;
  182.   int num;
  183.  
  184.   changed = False;
  185.   if (filename->changed()) {
  186.     pref->setFilename(filename->getValue());
  187.     changed = True;
  188.   }
  189.   if (advance->changed()) {
  190.     pref->setAdvanceWarning(advance->getValue());
  191. // add units
  192.     advance->setValue(pref->advanceWarning());
  193.     changed = True;
  194.   }
  195.   if (update->changed()) {
  196.     if ((num = atoi(update->getValue())) > 0) {
  197.       pref->setUpdateInterval(num);
  198.       changed = True;
  199.     } else {
  200.       theWarningDialog->post("Illegal update interval.");
  201.     }
  202.   }
  203.   if (lates->changed()) {
  204.     pref->setShowLates(lates->getValue());
  205.     changed = True;
  206.   }
  207.   if (autoSave->changed()) {
  208.     pref->setSaveChangesAutomatically(autoSave->getValue());
  209.     changed = True;
  210.   }
  211.   if (annotate->changed()) {
  212.     pref->setAnnotateFile(annotate->getValue());
  213.     changed = True;
  214.   }
  215.   if (updateIcon->changed()) {
  216.     pref->setUpdateIconName(updateIcon->getValue());
  217.     changed = True;
  218.   }
  219.   if (updateIconDate->changed()) {
  220.     pref->setUpdateIconDate(updateIconDate->getValue());
  221.     changed = True;
  222.   }
  223.   if (clock24->changed()) {
  224.     pref->setClock24(clock24->getValue());
  225.     changed = True;
  226.   }
  227.   if (alarms->changed()) {
  228.     pref->setAlarms(alarms->getValue());
  229.     changed = True;
  230.   }
  231.   if (notifyPopup->changed()) {
  232.     pref->setNotifyPopup(notifyPopup->getValue());
  233.     changed = True;
  234.   }
  235.   if (notifyBell->changed()) {
  236.     pref->setNotifyBell(notifyBell->getValue());
  237.     changed = True;
  238.   }
  239.   if (notifyMail->changed()) {
  240.     pref->setNotifyMail(notifyMail->getValue());
  241.     changed = True;
  242.   }
  243.   if (notifyConfirmDelete->changed()) {
  244.     pref->setNotifyConfirmDelete(notifyConfirmDelete->getValue());
  245.     changed = True;
  246.   }
  247.   if (notifyCommand->changed()) {
  248.     pref->setNotifyCommand(notifyCommand->getValue());
  249.     changed = True;
  250.   }
  251.   if (annotateDay->changed()) {
  252.     pref->setAnnotateDay(annotateDay->getValue());
  253.     changed = True;
  254.   }
  255.   if (snooze->changed()) {
  256.     if ((num = atoi(snooze->getValue())) > 0) {
  257.       pref->setSnoozeMinutes(num);
  258.       changed = True;
  259.     } else {
  260.       theWarningDialog->post("Illegal snooze time.");
  261.     }
  262.   }
  263.   if (hideMenu->changed()) {
  264.     pref->setHideMenuBar(hideMenu->getValue());
  265.     changed = True;
  266.     if (pref->hideMenuBar()) {
  267.       theWarningDialog->post("Menu bar will be hidden the next time you run vcal.");
  268.     } else {
  269.       theWarningDialog->post("Menu bar will be displayed the next time you run vcal.");
  270.     }
  271.   }
  272.   if (annotateMonth->changed()) {
  273.     pref->setAnnotateMonth(annotateMonth->getValue());
  274.     changed = True;
  275.   }
  276.   if (restricted->changed()) {
  277.     pref->setRestricted(restricted->getValue());
  278.     changed = True;
  279.   }
  280.   if (apptLength->changed()) {
  281.     if ((num = atoi(apptLength->getValue())) > 0) {
  282.       pref->setApptLength(num);
  283.       changed = True;
  284.     } else {
  285.       theWarningDialog->post("Illegal appointment length time.");
  286.     }
  287.   }
  288.   if (gridLength->changed()) {
  289.     if ((num = atoi(gridLength->getValue())) > 0) {
  290.       pref->setGridLength(num);
  291.       changed = True;
  292.     } else {
  293.       theWarningDialog->post("Illegal grid entry length.");
  294.     }
  295.   }
  296.   if (apptSubdiv->changed()) {
  297.     if ((num = atoi(apptSubdiv->getValue())) > 0) {
  298.       pref->setApptSubdiv(num);
  299.       changed = True;
  300.     } else {
  301.       theWarningDialog->post("Illegal number of grid subdivisions.");
  302.     }
  303.   }
  304.   if (snapInterval->changed()) {
  305.     if ((num = atoi(snapInterval->getValue())) > 0) {
  306.       pref->setSnapInterval(num);
  307.       changed = True;
  308.     } else {
  309.       theWarningDialog->post("Illegal grid snap interval.");
  310.     }
  311.   }
  312.   if (restrictStart->changed()) {
  313.     if ((num = atoi(restrictStart->getValue())) > 0) {
  314.       pref->setRestrictStart(num);
  315.       changed = True;
  316.     } else {
  317.       theWarningDialog->post("Illegal restricted start hour.");
  318.     }
  319.   }
  320.   if (restrictStop->changed()) {
  321.     if ((num = atoi(restrictStop->getValue())) > 0) {
  322.       pref->setRestrictStop(num);
  323.       changed = True;
  324.     } else {
  325.       theWarningDialog->post("Illegal restricted stop hour.");
  326.     }
  327.   }
  328.   if (changed) {
  329.     owner->prefChanged();
  330.   }
  331. }
  332.